#!/bin/bash 
#
# Copyright 2009 RedHat Inc. All rights reserved.
# Use is subject to license terms.
#
# Description:	  Logs collector for RHEV
# Input: 
#       uuid: added to output file for uniquness.
#
BASEDIR=/var/log
TMPDIR=$BASEDIR/qlogs
ERR=$TMPDIR/collectErrors.log
DESTINATION=$BASEDIR/qlogs-${1}.tar.bz2

if [ -x $TMPDIR ]; then
    rm -rf $TMPDIR
fi
if [ -f $BASEDIR/qlogs-*.tar.bz2 ]; then
    rm -f $BASEDIR/qlogs-*.tar.bz2
fi
touch $DESTINATION
mkdir -p $TMPDIR
echo `date` >> $ERR

printf "\n\n\n" | TMP=$TMPDIR /usr/sbin/sosreport --no-progressbar -o vdsm,general,networking,hardware,process,yum,filesys >> $ERR
RETVAL=$?
if [ "$RETVAL" -eq 0 ]; then
    mv $TMPDIR/*.tar.bz2 $DESTINATION
    rm -rf $TMPDIR
    exit 0
else
    echo "Could not archive logs" 
    echo "Could not archive logs" >> $ERR
    exit 1     
fi

